package com.jbinfo.qingcaowan.studyManager.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.jbinfo.common.utils.DataTables;
import com.jbinfo.common.utils.UUIDUtils;
import com.jbinfo.qingcaowan.studyManager.dao.StudyManagerDao;
import com.jbinfo.qingcaowan.studyManager.dto.BookInfoModel;
import com.jbinfo.qingcaowan.studyManager.entity.BookInfo;
import com.jbinfo.qingcaowan.studyManager.service.StudyManagerService;
/**
 * 
* @ClassName: UserServiceImpl 
* @Description: TODO 用户管理service实现类
* @author ZhangLei 
* @date 2016年6月22日 上午10:23:02
 */
@Service
public class StudyManagerServiceImpl implements StudyManagerService {

	@Autowired
	private StudyManagerDao studyManagerDao;

	@Override
	public DataTables<BookInfo> findByParam(BookInfoModel bookInfoModel) {
		String today = bookInfoModel.getShelvesTime();
		bookInfoModel.setShelvesTime1(today+" 00:00:00");
		bookInfoModel.setShelvesTime2(today+" 23:59:59");
		List<BookInfo> tList = studyManagerDao.findByParam(bookInfoModel);
		return DataTables.combinTotalRecords(tList);
	}

	@Override
	public void save(BookInfo bookInfo) {
		//处理书籍编号
		String bookId = UUIDUtils.create();
		bookInfo.setBookId(bookId);
		//所有的英文逗号换成中文逗号
		bookInfo.setAuthors(bookInfo.getAuthors().replace(",", "，"));
		bookInfo.setPress(bookInfo.getPress().replace(",", "，"));
		
		studyManagerDao.save(bookInfo);
		
	}

	@Override
	public BookInfo getBookInfo(String bookId) {
		return studyManagerDao.getBookInfo(bookId);
	}

	@Override
	public int editBook(BookInfo bookInfo) {
		//所有的英文逗号换成中文逗号
		bookInfo.setAuthors(bookInfo.getAuthors().replace(",", "，"));
		bookInfo.setPress(bookInfo.getPress().replace(",", "，"));
		return studyManagerDao.editBook(bookInfo);
	}

	@Override
	public int delBook(String bookId) {
		return studyManagerDao.delBook(bookId);
	}

}
